package com.holi.hiteacher.model;

import com.holi.hiteacher.bean.SchoolInfoVM;
import com.holi.hiteacher.data.DatabaseUtil;

/**
 * @description:
 * @author: JoshuaWong E-mail:joshuawongchn@gmail.com
 * @date: 2017年01月08日 20:31
 * @version: 1.0
 */

public class SchoolInfoModel {
    private SchoolInfoVM sVM = null;

    public SchoolInfoModel(SchoolInfoVM vm) {
        sVM = vm;
        sVM.setShow(false);
        sVM.setEmailCount(String.valueOf(0));
//        int count = DatabaseUtil.getUnreadCount();
//
//        sVM.setShow(count > 0);
//        sVM.setEmailCount(String.valueOf(count));
    }

    /**
     * 未读信息数 +1
     */
    public void countUp() {
        sVM.setShow(true);
        if (sVM != null) {
            int count = Integer.valueOf(sVM.getEmailCount()) + 1;
            sVM.setEmailCount(String.valueOf(count));
        }
    }

    /**
     * 未读信息数 -1
     */
    public void countDown() {
        if (sVM != null) {
            int count = Integer.valueOf(sVM.getEmailCount());
            count = Math.max(count - 1, 0);
            if (count == 0)
                sVM.setShow(false);
            sVM.setEmailCount(String.valueOf(count));
        }
    }

    /**
     * 更新未读信息数
     */
    public void updateCount() {
        if (sVM != null) {
            int count = DatabaseUtil.getUnreadCount();
            sVM.setShow(count > 0);
            sVM.setEmailCount(String.valueOf(count));
        }
    }

}
